define([
  'jquery',
  'underscore',
  'backbone',
  'dateformatter',
  'https://www.google.com/jsapi',
  'text!templates/charts/adminChartTemplate.html'
], function($, _, Backbone,Dateformatter, googlecharts,adminChartTemplate){

  var UnattendedView = Backbone.View.extend({
    el: $(".mainpanel"),
 //   events: {'click #savePayments' : 'savePayments', 'change .paymentamount':'addtomodel'} ,
    render: function(){
  	  var compiledTemplate = _.template( adminChartTemplate, null);
      this.$el.html(compiledTemplate);
      google.load('visualization', '1',  {'callback':this.drawCharts,
            'packages':['corechart','table']});
		
    },
    drawCharts: function(){
 	      
	      $.ajax({
		        type: "GET",
		        url: "/getGraphs",
		        success: function(data1){
		        	var chartData=[];
		        	var eachRow =[];
		        	var header = ['Department', 'Earnings'];
		        	chartData.push(header);
		        	var monthly = data1.current;
			  	      for(var i=0 in monthly){
				    	  eachRow = [monthly[i].speciality, monthly[i].amount ];
				    	  chartData.push(eachRow);
				      }
				      var data = google.visualization.arrayToDataTable(chartData);
			          // Create and draw the visualization.
				      
			          var chart = new google.visualization.BarChart(document.getElementById('monthly'));
			         
			          chart.draw(data,
			                   {title:"Current month earnings",
			                    width:800, height:600,
			                    vAxis: {title: "Department"},
			                    hAxis: {title: "Earnings"}}
			              );
			          

		        }
	    });

    }
  });

  return UnattendedView;
});
